/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#ifndef ALLIANCE_PROJECTSTREE_H
#define ALLIANCE_PROJECTSTREE_H

#include <wx/wx.h>
#include <wx/treectrl.h>

#include <map>

#include "alliance/include/project.h"

namespace alliance
{
    enum ImageType
    {
        WORKSPACE_IMG = 0,
        PROJECT_IMG,
        FILE_IMG,
        FILE_DELETED_IMG,
        FILE_MODIFIED_IMG,
        VIRTUAL_DIR_IMG
    };

    enum ItemType
    {
        PROJECT=1,
        FILE,
        VIRTUAL_DIR
    };

    typedef struct ItemData : public wxTreeItemData
    {
        ~ItemData();
        wxString path;
        ItemType type;
        Project *project;
    }ItemData;

    class ProjectsTree : public wxTreeCtrl
    {
        DECLARE_DYNAMIC_CLASS( alliance::ProjectsTree );

        friend struct ItemData;
    public:
        ProjectsTree();
        ProjectsTree( wxWindow *parent, const wxString &workspaceName );
        virtual ~ProjectsTree();

        void AddProject( Project *project );

        void AddFile( const wxString &filePath, const wxString &virtualDir, Project *project );

        void ActivateProject( const Project *project );

        bool IsActiveProject( const Project *project ) const;

        bool RemoveFile( const wxString &filePath, const Project *project );

        /**
        * @brief
        */
        void ReloadProject( Project *project );

        bool RemoveProject( const Project *project );
    protected:
    private:
        std::map<wxString, wxTreeItemId> m_mapElements;

        ItemData *m_itemData;

        void OnWorkspaceTreeActivated( wxTreeEvent &evt );

        void OnWorkspaceTreeRightClick( wxTreeEvent &evt );

        void ShowPopupMenuProject( ItemData *itemData );
        void OnPopupMenuProject( wxCommandEvent &evt );

        void ShowPopupMenuFile( ItemData *itemData );
        void OnPopupMenuFile( wxCommandEvent &evt );

        void AddVirtualDir( const wxString &virtualDir, Project *project );
        void DeactivateAllProjects();
        virtual int OnCompareItems( const wxTreeItemId &item1, const wxTreeItemId &item2 );
    };
}

#endif //ALLIANCE_PROJECTSTREE_H
